package com.person.controller;

import com.person.model.entity.Result;
import com.person.model.entity.User;
import com.person.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user,HttpServletRequest request) {
        User info = userService.login(user,request);
        if (info != null) {
            return Result.success(info);
        } else {
            return Result.error("用户名或密码错误");
        }
    }

    @GetMapping("/current")
    public Result current(HttpServletRequest request) {
        User info = userService.current(request);
        if (info != null) {
            return Result.success(info);
        } else {
            return Result.error("用户未登录");
        }
    }
}
